﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using Common;

public partial class System_RolesManageList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        PageBegin("system role admin");

        switch (RequestBase.GetFormString("otype"))
        {
            case "loaddata":
                LoadingData();
                break;
            case "delete":
                Delete();
                break;
        }
    }

    #region 信息绑定
    void LoadingData()
    {
        string ctrl = "~/admin/system/_controls/ctlRolesList.ascx";

        Control uc_rep = LoadControl(ctrl);

        Repeater rptRolesList = (Repeater)uc_rep.FindControl("rptRolesList");

        try
        {
            DataTable dt = BLL.CommonBLL.Select("System_Roles", "*", " ORDER BY LineNum ASC");

            rptRolesList.DataSource = dt;
            rptRolesList.DataBind();

            StringBuilder strb = new StringBuilder();
            StringWriter sw = new StringWriter(strb);
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            rptRolesList.RenderControl(htw);

            BLL.AjaxHelper.ResponseWrite(strb.ToString());
        }
        catch (System.Threading.ThreadAbortException err)
        {
            //nothing   to   do   
        }
        catch (Exception err)
        {
            BLL.AjaxHelper.ResponseWrite(err.Message);
        }
    }
    #endregion
 
    #region 删除角色
    void Delete()
    {
        string res = "";
        if (!Utils.IsGuid(RequestBase.GetFormString("roleid")))
        {
            res = "参数错误!";
        }
        else
        {
            res = BLL.SystemRoles.Delete(RequestBase.GetFormString("roleid"));
        }
        BLL.AjaxHelper.ResponseWrite(res);
    }
    #endregion
}
